package com.lalifa.base

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

/**
 *
 * @ClassName BaseFragment
 * @Author lanlan
 * @Email 985334276@qq.com
 * @Date 2022/6/30 17:09
 * @Des
 */
abstract class BaseFragment<T : ViewBinding>() : Fragment() {
    lateinit var binding: T
    fun isBindingInitialised() = this::binding.isInitialized

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        onClick()
    }
    //获取显示进度条
    internal var dialog: Dialog? = null
    @SuppressLint("InflateParams")
    fun getProgress(context: Context) {
        dialog = Dialog(context, R.style.MyDialog)
        dialog!!.show()
        dialog!!.window!!.setContentView(LayoutInflater.from(context).inflate(R.layout.progress, null))
        dialog!!.setCancelable(true)
    }

    //隐藏进度条
    fun hindProgress() {
        if (dialog != null) {
            dialog!!.dismiss()
        }
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = getViewBinding(inflater, container)
        return binding.root
    }

    abstract fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?): T
    abstract fun initView()
    open fun onClick() {}
}